#ifndef PathFinder_h__
#define PathFinder_h__
#include "../Detour/DetourNavMeshQuery.h"
#include "../Detour/DetourCommon.h"

#define SAFE_DELETE(p)	do { delete (p); (p) = NULL; } while(0)

typedef enum
{
	Model_PathFind_Follow,
	Model_PathFind_Straight,
	Model_PathFind_Sliced,
	Model_Raycast,
	Model_Distance_To_Wall,
	Model_Find_Polys_InCircle,
	Model_Find_Polys_In_Shape,
	Model_Find_Local_Neighbourhood
	
}FindMode;

enum SamplePolyFlags
{
	SAMPLE_POLYFLAGS_WALK = 0x01,		// Ability to walk (ground, grass, road)
	SAMPLE_POLYFLAGS_SWIM = 0x02,		// Ability to swim (water).
	SAMPLE_POLYFLAGS_DOOR = 0x04,		// Ability to move through doors.
	SAMPLE_POLYFLAGS_JUMP = 0x08,		// Ability to jump.
	SAMPLE_POLYFLAGS_DISABLED = 0x10,		// Disabled polygon
	SAMPLE_POLYFLAGS_ALL = 0xffff	// All abilities.
};
enum SamplePolyAreas
{
	SAMPLE_POLYAREA_GROUND,
	SAMPLE_POLYAREA_WATER,
	SAMPLE_POLYAREA_ROAD,
	SAMPLE_POLYAREA_DOOR,
	SAMPLE_POLYAREA_GRASS,
	SAMPLE_POLYAREA_JUMP,
};

class PathFinder 
{
public:
	static const int MAX_POLYS = 256;
	static const int MAX_SMOOTH = 2048;
public:
	PathFinder(dtNavMesh* navMesh, dtNavMeshQuery* navQuery);
	~PathFinder();	
	bool Find(float& sposX, float& sposY, float& sposZ, float& eposX, float& eposY, float& eposZ);
	float* GetPath(int* count);
	bool CalcNear(float& sposX,float& sposY, float& sposZ);
	float* GetNear(int* count);
	bool CalcRaycast(float& sposX, float& sposY, float& sposZ, float& eposX, float& eposY, float& eposZ);
	float* GetRaycast(int* count);
protected:
	void Reset();
private:
	dtNavMesh* m_navMesh;
	dtNavMeshQuery* m_navQuery;
	float m_polyPickExt[3] = {0.0f};
	dtQueryFilter m_filter;
	dtPolyRef m_polys[MAX_POLYS] = {0};
	float m_Path[MAX_POLYS * 3] = {0};
	float m_nearPos[3] = {0};
	int m_nearCount = {0};
	unsigned char m_PathFlags[MAX_POLYS] = {0};
	dtPolyRef m_PathPolys[MAX_POLYS] = {0};
	int m_npolys = { 0 };
	int m_nstraightPath = {0};
	float m_hitPos[3] = {0.0f};
	int m_hitCount = {0};
};
#endif // PathFinder_h__
